package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.OrderStatusDTO;
import com.itheima.pojo.OrderVO;
import com.itheima.pojo.SetmealNumber;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 预约列表分页查询
     * @param queryPageBean
     * @return
     */
    Page<OrderVO> pageQuery(QueryPageBean queryPageBean);

    /**
     * 修改预约状态
     * @param orderStatusDTO
     */
    @Update("update t_order set orderStatus = #{orderStatus} where id = #{id}")
    void updateStatus(OrderStatusDTO orderStatusDTO);

    /**
     * 获取套餐id
     * @return
     */
    @Select("select setmeal_id from t_order group by setmeal_id")
    List<Integer> getSetmealName();


    /**
     * 获取套餐预约数
     * @param setmealId
     * @return
     */
    @Select("select count(*) from t_order where setmeal_id = #{setmealId} group by setmeal_id")
    Integer getSetmealId(@Param("setmealId") Integer setmealId);

    /**
     * 当前时间预约数
     * @param reportDate
     * @return
     */
    @Select("select count(*) from t_order where orderDate = #{reportDate}")
    Integer getTodayNew(@Param("reportDate")Date reportDate);

    /**
     * 获取当前周的预约
     * @param beginWeek
     * @param endWeek
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= #{beginWeek} and orderDate <= #{endWeek}")
    Integer getWeekNew(@Param("beginWeek") Date beginWeek, @Param("endWeek") Date endWeek);

    /**
     * 获取当前月的预约
     * @param beginMonth
     * @param reportDate
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= #{beginMonth} and orderDate <= #{reportDate}")
    Integer getMonthNew(@Param("beginMonth") Date beginMonth, @Param("reportDate") Date reportDate);

    /**
     * 当前月到诊数
     * @param beginMonth
     * @param reportDate
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= #{beginMonth} and orderDate <= #{reportDate} and orderType = '已到诊'")
    Integer getMonthVisits(@Param("beginMonth") Date beginMonth, @Param("reportDate") Date reportDate);

    /**
     * 获取当前周的到诊数
     * @param beginWeek
     * @param endWeek
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= #{beginWeek} and orderDate <= #{endWeek} and orderType = '已到诊'")
    Integer getWeekVisits(@Param("beginWeek") Date beginWeek, @Param("endWeek") Date endWeek);

    /**
     * 当前时间到诊数
     * @param reportDate
     * @return
     */
    @Select("select count(*) from t_order where orderDate = #{reportDate} and orderType = '已到诊'")
    Integer getTodayVisits(@Param("reportDate")Date reportDate);

    /**
     * 获取总数
     * @return
     */
    @Select("select count(*) from t_order ")
    Integer getSum();
}
